# forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from .models import UserProfile,Member,MyGame,TeamMatch,gametest
class MyUserCreationForm(UserCreationForm):
    email = forms.EmailField(required=True)
    class Meta:
        model = User
        fields = ("username", "email", "password1", "password2")
    def save(self, commit=True):
        # 保存用户之前，先保存email
        user = super(MyUserCreationForm, self).save(commit=False)
        user.email = self.cleaned_data["email"]
        if commit:
            user.save()
        return user
class LoginForm(forms.Form):
    username = forms.CharField(max_length=150)
    password = forms.CharField(widget=forms.PasswordInput)
class UserDetailForm(forms.ModelForm):
    class Meta:
        model=UserProfile
        exclude=['user']
class MemberForm(forms.ModelForm):
    class Meta:
        model=Member
        exclude=[]
class GameForm(forms.ModelForm):
    class Meta:
        model=MyGame
        fields=["date","location","state"]

class GametestForm(forms.ModelForm):
    class Meta:
        model=gametest
        fields=['time']

